package com.chat.admin.domain.VO;

import com.chat.admin.domain.pojo.Meta;
import com.chat.admin.domain.pojo.RouteConfigsTable;
import com.chat.common.entity.RouteInfo;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * RouteVO: 用于在前端显示的数据对象
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RouteVO implements Serializable {
    private String path;
    private String name;
    private String component;
    private Integer rank;
    private Meta meta;
    // 用于存储子路由的列表。对于没有子路由的路由来说，该列表为空
    private List<RouteVO> children;

    public RouteVO(RouteConfigsTable routeConfigsTable) {
        this.path = routeConfigsTable.getPath();
        this.name = routeConfigsTable.getName();
        this.component = routeConfigsTable.getComponent();
        this.meta = routeConfigsTable.getMeta();
        if (routeConfigsTable.getChildren() != null) {
            this.children = routeConfigsTable.getChildren().stream().map(RouteVO::new).collect(Collectors.toList());
        } else {
            this.children = null;
        }
    }
}